package com.lagou.edu.course.controller;

import com.lagou.edu.course.api.dto.MediaDTO;
import com.lagou.edu.course.api.dto.VideoPlayDto;
import com.lagou.edu.course.remote.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author lm
 * @since 2021/11/1 16:24
 */
@Slf4j
@RestController
@RequestMapping("/course/media")
public class MediaController {
    @Autowired
    MediaService mediaService;

    /**
     * 根据课时ID获取播放媒体信息
     *
     * @param lessonId 课时ID
     * @return
     */
    @GetMapping(value = "/getMediaByLessonId")
    public MediaDTO getMediaByLessonId(@RequestParam("lessonId") Integer lessonId) {
        return mediaService.getMediaByLessonId(lessonId);
    }

    /**
     * 更新或者保存媒体
     */
    @PostMapping("/updateOrSaveMedia")
    void updateOrSaveMedia(@RequestBody MediaDTO courseMediaDTO) {
        mediaService.updateOrSaveMedia(courseMediaDTO);
    }

    /**
     * 获取是媒体播放信息
     */
    @GetMapping("/getVideoPlayInfo")
    VideoPlayDto getVideoPlayInfo(@RequestParam("lessonId") Integer lessonId, @RequestParam(required = false, value = "userId") Integer userId) {
        return mediaService.getVideoPlayInfo(lessonId, userId);
    }
}
